package com.cy.advice;

import com.cy.common.pojo.RestResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * Description: 全局异常处理类
 * date: 2021/3/19 0019 17:40
 *
 * @author Mr.xiaoshi
 * @since JDK 1.8
 */
@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {
    /*@ExceptionHandler(ShiroException.class)
    public JsonResult doShiroException(ShiroException e){
        JsonResult r=new JsonResult();
        r.setState(0);
        if(e instanceof UnknownAccountException){
            r.setMessage("用户名不存在");
        }else if(e instanceof IncorrectCredentialsException){
            r.setMessage("密码不正确");
        }else if(e instanceof LockedAccountException){
            r.setMessage("账户被锁定");
        }else if(e instanceof AuthorizationException){
            r.setMessage("没有权限");
        }else{
            r.setMessage("认证或授权失败");
        }
        return r;
    }*/

    @ExceptionHandler(RuntimeException.class)
    public RestResult doHandleRuntimeException(RuntimeException e){
        log.error("Exception: {}"+e.getMessage());
        e.printStackTrace();
        return new RestResult(e);
    }
}
